package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CutomerDrain;
import cn.wolfcode.crm.query.FailPlanListQueryObject;
import cn.wolfcode.crm.service.ICutomerDrainService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("cutomerDrain")
public class CutomerDrainController {
    @Autowired
    private ICutomerDrainService cutomerDrainService;

    @RequestMapping("view")
    @RequiresPermissions(value = {"cutomerDrain:view", "客户流失页面"}, logical = Logical.OR)
    public String view() {
        return "client/cutomerDrain";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(FailPlanListQueryObject qo) {
        return cutomerDrainService.list(qo);
    }

    @RequestMapping("lossOfCustomers")
    @ResponseBody
    @RequiresPermissions(value = {"cutomerDrain:lossOfCustomers","客户流失"},logical = Logical.OR)
    public JsonResult lossOfCustomers(CutomerDrain obj) {
        try {
            cutomerDrainService.lossOfCustomers(obj);
            return JsonResult.success("流失成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.mark("流失失败");
        }
    }
}
